package com.adms.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.adms.domain.Circular;
import com.adms.service.CircularService;

@RequestMapping("circular")
@RestController
public class CircularController {

	@Autowired
	private CircularService circularService;
	
	@GetMapping("{circularId}")
	public Object getByCircularId(@PathVariable("circularId") Integer circularId) {
		return circularService.getByCircularId(circularId);
	}
	
	@GetMapping("getWithCanReply")
	public Object getByCircularIdWithCanReply(@RequestParam("circularId") Integer circularId) {
		return circularService.getByCircularIdWithCanReply(circularId);
	}
	
	@GetMapping
	public Object list(Circular circular,Boolean isSelf,String timeField,Date start,Date end,String key,String orderByClause,
			@RequestParam(defaultValue = "1") Integer pageNum,
			@RequestParam(defaultValue = "5") Integer pageSize,
			@RequestParam(defaultValue = "5") Integer navigatePages) {
		return circularService.list(circular,isSelf,timeField,start,end,key,orderByClause,pageNum,pageSize,navigatePages);
	}
	
	@GetMapping("listWithCanReply")
	public Object listWithCanReply(Circular circular,Boolean isSelf,String timeField,Date start,Date end,String key,String orderByClause,
			@RequestParam(defaultValue = "1") Integer pageNum,
			@RequestParam(defaultValue = "5") Integer pageSize,
			@RequestParam(defaultValue = "5") Integer navigatePages) {
		return circularService.listWithCanReply(circular,isSelf,timeField,start,end,key,orderByClause,pageNum,pageSize,navigatePages);
	}
	
	@GetMapping("count")
	public Object count(String timeField,Date start,Date end) {
		return circularService.count(timeField, start, end);
	}
	
	@PostMapping("publish")
	public Object publish(Circular circular,MultipartFile[] files) {
		return circularService.publish(circular,files);
	}
	
	@PostMapping("respond")
	public Object respond(@RequestParam("circularId") Integer circularId,String content,String signature) {
		return circularService.respond(circularId,content,signature);
	}

	@PostMapping("update")
	public Object update(Circular circular) {
		return circularService.update(circular);
	}
		
	@PostMapping("delete")
	public Object delete(@RequestParam("circularIds") int[] circularIds) {
		return circularService.delete(circularIds);
	}
}
